home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * grabber cdev
- *
- * Copyright © 1990 Michael Kahl.
- *
- */
-
- #include <VRetraceMgr.h>
-
- #include "grabber_cdev.h"
-
- static void *FindVBL(void);
-
-
- /* item numbers */
- enum {
- iTitle = 1,
- iEnabled,
- iMomentum,
- iFriction,
- iControl,
- iShift,
- iCommand,
- iOption,
- iCapsLock
- };
-
-
- /*
- * New - create the cdev object
- *
- */
-
- cdev *
- New()
- {
- return(new(grabber_cdev));
- }
-
-
- /*
- * Runnable - should the cdev appear in the Control Panel?
- *
- * This implements the "macDev" message. If the INIT was not installed,
- * we don't want the cdev to show up in the Control Panel.
- *
- */
-
- Boolean
- Runnable()
- {
- return(FindVBL() != 0);
- }
-
-
- /*
- * grabber_cdev::Init
- *
- */
-
- void
- grabber_cdev::Init()
- {
- inherited::Init();
-
- /* get pointer to options record */
-
- opt = FindVBL();
-
- /* set up checkboxes from options */
-
- if (opt->enabled)
- SetCtlValue(GetCheckBox(iEnabled), 1);
- if (opt->momentum)
- SetCtlValue(GetCheckBox(iMomentum), 1);
- if (opt->friction)
- SetCtlValue(GetCheckBox(iFriction), 1);
- if (opt->control)
- SetCtlValue(GetCheckBox(iControl), 1);
- if (opt->shift)
- SetCtlValue(GetCheckBox(iShift), 1);
- if (opt->command)
- SetCtlValue(GetCheckBox(iCommand), 1);
- if (opt->option)
- SetCtlValue(GetCheckBox(iOption), 1);
- if (opt->capsLock)
- SetCtlValue(GetCheckBox(iCapsLock), 1);
- }
-
-
- /*
- * grabber_cdev::ItemHit
- *
- */
-
- void
- grabber_cdev::ItemHit(item)
- int item;
- {
- ControlHandle check = GetCheckBox(item);
- int value = 1 - GetCtlValue(check);
- Handle r;
-
- SetCtlValue(check, value);
-
- /* update options record */
-
- switch (item) {
- case iEnabled:
- opt->enabled = value;
- break;
- case iMomentum:
- opt->momentum = value;
- break;
- case iFriction:
- opt->friction = value;
- break;
- case iControl:
- opt->control = value;
- break;
- case iShift:
- opt->shift = value;
- break;
- case iCommand:
- opt->command = value;
- break;
- case iOption:
- opt->option = value;
- break;
- case iCapsLock:
- opt->capsLock = value;
- break;
- }
-
- /* update options resource */
-
- if (r = Get1Resource('cnfg', 0)) {
- * (struct opt *) *r = *opt;
- ChangedResource(r);
- }
- }
-
-
- /*
- * grabber_cdev::GetCheckBox
- *
- */
-
- ControlHandle
- grabber_cdev::GetCheckBox(int item)
- {
- int type;
- ControlHandle check;
- Rect box;
-
- GetDItem(dp, lastItem + item, &type, &check, &box);
- return(check);
- }
-
-
- /*
- * FindVBL - get pointer to options record
- *
- * The INIT has left a trail of bread crumbs so we can find it in memory.
- * We search the vertical retrace queue looking for its signature, which
- * looks like:
- *
- * dc.l ?? ; ==> options record
- * dc.l 'grab' ; signature
- * dc.l 'INIT' ; signature
- * ; VBL code starts here
- *
- * (The VBL task itself doesn't do anything, other than reset its count whenever
- * it runs down so that it will remain in the queue.)
- *
- */
-
- static void *
- FindVBL(void)
- {
- register VBLQElPtr p;
- register void *q;
-
- for (p = (VBLQElPtr) VBLQueue.qHead; p; p = (VBLQElPtr) p->qLink) {
- q = p->vblAddr;
- asm {
- cmpi.l #'INIT',-(q)
- bne @1
- cmpi.l #'grab',-(q)
- bne @1
- move.l -(q),d0
- return
- @1 }
- }
- return(0); /* not found - INIT must not have run */
- }
-